<?php 

include '../function.php';

$link = @new mysqli('localhost','root','','school');

if($link->connect_errno){
	exit("失败:".$link->connect_errno.":".$link->connect_error);
}

$link->query("set names utf8");

// $sql = "select * from  stu1";

// // $sql = "select stu.name,class.classname from stu left join class on stu.cid=class.id";
// $result = $link->query($sql);


// $tempArr = array();

// while ($row = $result->fetch_assoc()) {
// 	$tempArr[]=$row;
// }

// var_dump($tempArr);


//  $result->free();



// $sql = "insert into stu (name,qq) value('??','??')";


// $result = $link->query($sql);

// var_dump($link->insert_id);



$sql = "insert into stu (name,cid) values(?,?)";

$stmt = $link->prepare($sql);


if (!$stmt) {
	printf("<b>发生错误:</b>%s", $link->error);
} else {
	$stmt->bind_param("ss", $name, $cid); //绑定参数
	$arr = array("name" => "王五", "cid" =>'1');	
	extract($arr);

	if ($stmt->execute()) {	
		printf("影响的条数%s<br/>", $stmt->affected_rows);	
		printf("最后揑入的%s<br/>", $stmt->insert_id);	
	} else {		
		printf("错误代码:%s,<br/>错误内容:%s", 
			$stmt->errno,$stmt->error);	
	}	

	$stmt->close();	

}

 $link->close();



 ?>